package org.ascollada.core
{
	public class DaeMatrix
	{
		public var values :Array;
		
		/**
		 * 
		 */ 
		public function DaeMatrix(values:Array=null)
		{		
			if(values && values.length == 16)
			{
				this.values = values;
				
			}
			else
			{
				this.values = [
					1, 0, 0, 0,
					0, 1, 0, 0,
					0, 0, 1, 0,
					0, 0, 0, 1
				];
			}
		}
		
		/**
		 * 
		 */ 
		public function calculateMultiply(ma:DaeMatrix, mb:DaeMatrix):void
		{
			var a :Array = ma.values;
			var b :Array = mb.values;
			
			var a11:Number = a[0]; var b11:Number = b[0];
			var a12:Number = a[1]; var b12:Number = b[1];
			var a13:Number = a[2]; var b13:Number = b[2];
			var a14:Number = a[3]; var b14:Number = b[3];
			var a21:Number = a[4]; var b21:Number = b[4];
			var a22:Number = a[5]; var b22:Number = b[5];
			var a23:Number = a[6]; var b23:Number = b[6];
			var a24:Number = a[7]; var b24:Number = b[7];
			var a31:Number = a[8]; var b31:Number = b[8];
			var a32:Number = a[9]; var b32:Number = b[9];
			var a33:Number = a[10]; var b33:Number = b[10];
			var a34:Number = a[11]; var b34:Number = b[11];
			
			this.values[0] = a11*b11+a12*b21+a13*b31;
			this.values[1] = a11*b12+a12*b22+a13*b32;
			this.values[2] = a11*b13+a12*b23+a13*b33;
			this.values[3] = a11*b14+a12*b24+a13*b34+a14;
			this.values[4] = a21*b11+a22*b21+a23*b31;
			this.values[5] = a21*b12+a22*b22+a23*b32;
			this.values[6] = a21*b13+a22*b23+a23*b33;
			this.values[7] = a21*b14+a22*b24+a23*b34+a24;
			this.values[8] = a31*b11+a32*b21+a33*b31;
			this.values[9] = a31*b12+a32*b22+a33*b32;
			this.values[10] = a31*b13+a32*b23+a33*b33;
			this.values[11] = a31*b14+a32*b24+a33*b34+a34;
			this.values[12] = 0;
			this.values[13] = 0;
			this.values[14] = 0;
			this.values[15] = 1;
		}
		
		/**
		 * 
		 */ 
		public static function multiply(a:DaeMatrix, b:DaeMatrix):DaeMatrix
		{
			var m :DaeMatrix = new DaeMatrix();
			m.calculateMultiply(a, b);
			return m;
		}
	}
}